package gqz.testdemo;

import android.app.Activity;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
 * Created by Administrator on 2018/8/24.
 */

public class TextViewTest extends Activity {

    private TextView tv;
    private EditText et_text, et_size;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tvtest);
        initView();
    }

    private void initView() {
        tv = findViewById(R.id.tvtest_tv_text);
        et_text = findViewById(R.id.tvtest_et_text);
        et_size = findViewById(R.id.tvtest_et_size);
    }

    public void onclick(View v) {
        switch (v.getId()) {
            case R.id.tvtest_btn_setText:
                tv.setText(et_text.getText());
                break;
            case R.id.tvtest_btn_setSize:
                String size = et_size.getText().toString();
                tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Integer.parseInt(size));
                break;
            case R.id.tvtest_btn_setNormal:
//                tv.getPaint().setFakeBoldText(false);
//                tv.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                tv.setPaintFlags(Paint.ANTI_ALIAS_FLAG);
                break;
            case R.id.tvtest_btn_setBold:
//                tv.getPaint().setFakeBoldText(true);
//                tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tv.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                break;
            case R.id.tvtest_btn_setSimsun:
                tv.setVisibility(View.VISIBLE);
                break;
            case R.id.tvtest_btn_setHeiti:
                tv.setVisibility(View.GONE);
                break;
        }
    }
}
